package com.cws.service;

import java.io.File;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.cws.enmu.RspCode;
import com.cws.frame.exception.CWSException;
import com.cws.model.Spots;

public class SpotService {

	private static final Logger log = LoggerFactory.getLogger(SpotService.class);

	private static final SpotService instance = new SpotService();

	private SpotService() {
	}

	public static SpotService getInstance() {
		return instance;
	}

	public File getVoiceFileById(String spotsId) {
		Spots spot = Spots.dao.findById(spotsId);

		String filePath = spot.getStr("voicePath");

		if (null == filePath || "".equals(filePath.trim())) {
			throw new CWSException(RspCode.FILE_NOT_EXIST);
		}

		File f = new File(filePath);
		//System.out.println("filePath:"+filePath);
		if (!f.exists()) {
			log.error("voice file not exist.");
			throw new CWSException(RspCode.FILE_NOT_EXIST);
		}

		return f;
	}
}
